from fastapi import APIRouter, Depends
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy import text

from app.db.session import get_db

router = APIRouter()

@router.get("/health/db")
async def db_health_check(db: AsyncSession = Depends(get_db)):
    """
    Checks if a connection to the database can be established.
    """
    try:
        await db.execute(text("SELECT 1"))
        return {"status": "ok", "message": "Database connection successful."}
    except Exception as e:
        return {"status": "error", "message": f"Database connection failed: {e}"}
